package de.koller.planet2D.frame.rendering;

import de.koller.planet2D.PNode;
import de.koller.planet2D.aRenderer.Renderer;
import de.koller.planet2D.rcom.RemovePNode;
import javax.swing.JProgressBar;

public class Renderizer extends PNode {

	private final RenderizerComp comp = new RenderizerComp( this );
	private Renderer renderer;
	
	@Override
	protected void init() {
		super.init();
		comp.setVisible( true );

		this.proot.previewFrame.comp.setEnabled( false );
	}

	@Override
	protected void release() {
		super.release();
		
		this.comp.dispose();
	}
	
	public void closeThis() {
		if( renderer == null ) {
			proot.call( new RemovePNode( this ) );
			this.proot.previewFrame.comp.setEnabled( true );
		}
	}
	
	public void renderNow( String name, int width, int height ) {
		this.comp.w.setEnabled( false );
		this.comp.h.setEnabled( false );
		this.comp.name.setEnabled( false );
		this.comp.renderStart.setEnabled( false );
		renderer = new Renderer( this, name, width, height );
	}
	
	public void readyRendered() {
		renderer = null;
		closeThis();
	}
	
	public JProgressBar getProgress() {
		return this.comp.progress;
	}
}
